<template>
	<view class="page">
		<Calendar :dataSource="data.all" @clickChange="handleTodaySign"></Calendar>

	</view>
</template>

<script setup>
	import {
		t
	} from '@/locale/index'
	import Calendar from "./components/j-calendar.vue";
	const {
		proxy
	} = getCurrentInstance();

	const data = ref({
		today: null,
		all: []
	});

	// 获取签到信息
	const loadData = () => {
		proxy.$http.get(`sign_in`).then(res => {
			res.data.all = res.data.all.map(item => item.sign_date);
			// console.log(res, "获取签到信息");

			data.value = res.data;
		})
	}
	// 今日签到
	const handleTodaySign = (date) => {
		if (!data.value.today) {
			proxy.$http.post(`sign_in`).then(res => {
				loadData();
				// console.log(date, "今日签到");
				proxy.$util.msg(t("account.sign-in.sign_in_success"));
			});
		}
	}
	loadData();
</script>

<style scoped lang="scss">
</style>